package com.youku.data
{
   import com.youku.interfaces.IPlayerData;
   import com.youku.interfaces.ICore;
   import com.youku.GlobalService;
   import com.youku.GlobalServiceKeys;
   import com.youku.interfaces.IConductor;
   import com.youku.interfaces.IPlayListData;
   import com.youku.ViewManager;
   import com.youku.ExternalProxy;
   import com.youku.interfaces.IRootData;
   import com.youku.PlayerConfig;
   import com.youku.constants.IKuActions;
   import com.youku.interfaces.IFolderData;
   import com.youku.interfaces.IShowData;
   import com.youku.interfaces.IVideoSegmentData;
   import com.youku.utils.PlayListUtil;
   import com.youku.interfaces.IDVDData;
   import com.youku.interfaces.ITrialData;
   import com.youku.interfaces.IThreeDData;
   import com.youku.interfaces.ICaptionData;
   import com.youku.interfaces.IVideoSegmentStatus;
   import com.youku.interfaces.IUserData;
   
   public class PlayerData extends Object implements IPlayerData
   {
      
      public function PlayerData() {
         super();
      }
      
      protected function get core() : ICore {
         return GlobalService.getService(GlobalServiceKeys.CORE) as ICore;
      }
      
      protected function get conductor() : IConductor {
         return GlobalService.getService(GlobalServiceKeys.CONDUCTOR) as IConductor;
      }
      
      protected function get playlistData() : IPlayListData {
         return GlobalService.getService(GlobalServiceKeys.PLAYLIST_DATA) as IPlayListData;
      }
      
      protected function get viewManager() : ViewManager {
         return GlobalService.getService(GlobalServiceKeys.VIEW_MANAGER) as ViewManager;
      }
      
      protected function get externalProxy() : ExternalProxy {
         return GlobalService.getService(GlobalServiceKeys.EXTERNALINTERFACE_PROXY) as ExternalProxy;
      }
      
      protected function get rootData() : IRootData {
         return PlayerConfig.rootData;
      }
      
      public function get GUID() : String {
         return PlayerConfig.GUID;
      }
      
      public function get isTouchPlayer() : Boolean {
         return PlayerConfig.isTouchPlayer;
      }
      
      public function get isRtmpPlayer() : Boolean {
         return PlayerConfig.isRTMP;
      }
      
      public function get isAutoPlay() : Boolean {
         if(this.rootData != null)
         {
            return this.rootData.autoPlay;
         }
         return false;
      }
      
      public function get isIKuInstall() : Boolean {
         var _loc1_:String = this.getIkuState(IKuActions.IFINST);
         return this.getIkuNormal(_loc1_);
      }
      
      public function get isIKuAllowPreload() : Boolean {
         var _loc1_:String = this.getIkuState(IKuActions.PRELOAD);
         return this.getIkuNormal(_loc1_);
      }
      
      public function get isIKuCanLoad() : Boolean {
         var _loc1_:String = this.getIkuState(IKuActions.LOAD);
         return this.getIkuNormal(_loc1_);
      }
      
      public function get isIKuCanSendLog() : Boolean {
         var _loc1_:String = this.getIkuState(IKuActions.LOG);
         return this.getIkuNormal(_loc1_);
      }
      
      public function getIkuState(param1:String) : String {
         return this.externalProxy.getIKuState(param1);
      }
      
      private function getIkuNormal(param1:String) : Boolean {
         if(param1 == null || param1 == "" || param1 == "0")
         {
            return false;
         }
         return true;
      }
      
      public function get IkuFlag() : String {
         return this.externalProxy.IkuFlag;
      }
      
      public function get IKuId() : String {
         return this.externalProxy.IKuId;
      }
      
      public function get href() : String {
         return this.externalProxy.getHref();
      }
      
      public function get referrer() : String {
         return this.externalProxy.getReferrer();
      }
      
      public function get videoIsPause() : Boolean {
         if(this.core == null)
         {
            return true;
         }
         return this.core.isPause;
      }
      
      public function get videoIdUncode() : String {
         if(this.playlistData == null)
         {
            return null;
         }
         return this.playlistData.videoId;
      }
      
      public function get videoIdEncode() : String {
         if(this.playlistData == null)
         {
            return null;
         }
         return this.playlistData.vidEncoded;
      }
      
      public function get videoTitle() : String {
         if(this.playlistData == null)
         {
            return null;
         }
         return this.playlistData.title;
      }
      
      public function get videoTags() : Array {
         if(this.playlistData == null)
         {
            return [];
         }
         return this.playlistData.tags;
      }
      
      public function get videoLogoURL() : String {
         if(this.playlistData == null)
         {
            return null;
         }
         return this.playlistData.logo;
      }
      
      public function get videoCt() : String {
         if(this.playlistData == null)
         {
            return "";
         }
         return this.playlistData.ct;
      }
      
      public function get videoFolder() : IFolderData {
         if(this.playlistData == null)
         {
            return null;
         }
         return this.playlistData.folder;
      }
      
      public function get videoShow() : IShowData {
         if(this.playlistData == null)
         {
            return null;
         }
         return this.playlistData.show;
      }
      
      public function get videoVolume() : Number {
         if(this.core == null)
         {
            return 0;
         }
         return this.core.volume;
      }
      
      public function get videoNsTime() : Number {
         if(this.core == null)
         {
            return 0;
         }
         return this.core.getNsTime();
      }
      
      public function get videoTotalTime() : Number {
         if(this.playlistData == null)
         {
            return 0;
         }
         return this.playlistData.totalTime;
      }
      
      public function get videoLoadedTime() : Number {
         if(this.core == null)
         {
            return 0;
         }
         return this.core.loadedTime;
      }
      
      public function get diffLoadedBytes() : Number {
         if(this.core == null)
         {
            return 0;
         }
         return this.core.diffLoadedBytes;
      }
      
      public function get videoLoadedBytes() : Number {
         if(this.core == null)
         {
            return 0;
         }
         return this.core.loadedBytes;
      }
      
      public function get droppedFrames() : Number {
         if(this.core == null)
         {
            return 0;
         }
         return this.core.droppedFrames;
      }
      
      public function get droppedFramesDifference() : Number {
         if(this.core == null)
         {
            return 0;
         }
         return this.core.dropFrameTable.difference;
      }
      
      public function get baseLoadedBytes() : Number {
         if(this.core == null)
         {
            return 0;
         }
         return this.core.baseLoadedBytes;
      }
      
      public function get videoCurrentLoadedTime() : Number {
         if(this.core == null)
         {
            return 0;
         }
         return this.core.currentLoadedTime;
      }
      
      public function get videoCurrentFileid() : String {
         if(this.core == null)
         {
            return "";
         }
         return this.core.currentFileId;
      }
      
      public function get currentVideoNum() : Number {
         if(this.core == null)
         {
            return -1;
         }
         return this.core.currentVideoNum;
      }
      
      public function get currentLoadingNum() : Number {
         if(this.core == null)
         {
            return -1;
         }
         return this.core.currentLoadingNum;
      }
      
      public function get videoCurrentNsTime() : Number {
         if(this.core == null)
         {
            return 0;
         }
         return this.core.currentNsTime;
      }
      
      public function get videoCurrentTotalTime() : Number {
         if(this.core == null)
         {
            return 0;
         }
         return this.core.currentTotalTime;
      }
      
      public function get videoCurrentWidth() : Number {
         if(this.core == null)
         {
            return 0;
         }
         return this.core.currentVideoWidth;
      }
      
      public function get videoCurrentHeight() : Number {
         if(this.core == null)
         {
            return 0;
         }
         return this.core.currentVideoHeight;
      }
      
      public function get videoCurrentRealWidth() : Number {
         if(this.core == null)
         {
            return 0;
         }
         return this.core.currentVideoRealWidth;
      }
      
      public function get videoCurrentRealHeight() : Number {
         if(this.core == null)
         {
            return 0;
         }
         return this.core.currentVideoRealHeight;
      }
      
      public function get currentState() : String {
         if(this.conductor == null)
         {
            return "";
         }
         return this.conductor.currentState;
      }
      
      public function get isInFullScreen() : Boolean {
         return this.viewManager.isInFullScreen;
      }
      
      public function get isContinuous() : Boolean {
         return this.rootData.continuous;
      }
      
      public function get isJump() : Boolean {
         return this.rootData.jump;
      }
      
      public function get playlistTotalTime() : Number {
         if(this.playlistData == null)
         {
            return 0;
         }
         return this.playlistData.totalTime;
      }
      
      public function get playlistTypeArr() : Array {
         if(this.playlistData == null)
         {
            return new Array();
         }
         return this.playlistData.typeArr;
      }
      
      public function getPreVideoURLByTime(param1:Number) : String {
         var _loc10_:IVideoSegmentData = null;
         var _loc11_:String = null;
         var _loc2_:Object = this.core.getTimeStatus(param1,"flv");
         if(_loc2_ == null)
         {
            return "";
         }
         var _loc3_:IVideoSegmentData = _loc2_.seg;
         var _loc4_:Number = _loc2_.internalTime;
         var _loc5_:String = _loc3_.basePrevFileURL;
         var _loc6_:String = _loc3_.key;
         var _loc7_:String = _loc3_.fileId;
         if(_loc3_.type != "flv")
         {
            _loc10_ = this.playlistData.videoSegmentsDic["flv"][_loc3_.no];
            _loc5_ = _loc10_.basePrevFileURL;
            _loc6_ = _loc10_.key;
            _loc7_ = _loc10_.fileId;
         }
         var _loc8_:String = _loc5_;
         _loc8_ = _loc8_ + ("?start=" + int(_loc4_ < 0?0:_loc4_));
         _loc8_ = _loc8_ + ("&K=" + _loc6_);
         _loc8_ = _loc8_ + ("&ctype=" + PlayerConstant.CTYPE);
         _loc8_ = _loc8_ + ("&ev=" + PlayerConstant.EV);
         _loc8_ = _loc8_ + ("&token=" + this.playlistData.tk);
         _loc8_ = _loc8_ + ("&oip=" + this.playlistData.oip);
         var _loc9_:String = this.playlistData.sid + "_" + _loc7_ + "_" + this.playlistData.tk;
         _loc9_ = _loc9_ + ("_" + PlayerConfig.bctime);
         _loc11_ = PlayListUtil.getInstance().changeSize(_loc9_);
         _loc8_ = _loc8_ + ("&ep=" + PlayListUtil.getInstance().setSize(_loc9_ + "_" + _loc11_.substr(0,4)));
         return _loc8_;
      }
      
      public function get videoListPreVideo() : Object {
         if(this.playlistData == null)
         {
            return null;
         }
         return this.playlistData.programList.preVideo;
      }
      
      public function get videoListNextVideo() : Object {
         if(this.playlistData == null)
         {
            return null;
         }
         return this.playlistData.programList.nextVideo;
      }
      
      public function get videoListPrograms() : Array {
         if(this.playlistData == null)
         {
            return null;
         }
         return this.playlistData.programList.videoList;
      }
      
      public function get dvdinfo() : IDVDData {
         if(this.playlistData == null)
         {
            return null;
         }
         return this.playlistData.dvdinfo;
      }
      
      public function get trialInfo() : ITrialData {
         if(this.playlistData == null)
         {
            return null;
         }
         return this.playlistData.trial;
      }
      
      public function get threedInfo() : IThreeDData {
         if(this.playlistData == null)
         {
            return null;
         }
         return this.playlistData.threeD;
      }
      
      public function get captionInfo() : ICaptionData {
         if(this.playlistData == null)
         {
            return null;
         }
         return this.playlistData.caption;
      }
      
      public function get playlistCurrentQuality() : String {
         if(this.playlistData == null)
         {
            return "";
         }
         return this.playlistData.fileType;
      }
      
      public function get playlistCurrentLang() : String {
         if(this.playlistData == null)
         {
            return "";
         }
         return this.playlistData.currentLang;
      }
      
      public function get playlistCurrentLangID() : String {
         if(this.playlistData == null)
         {
            return "";
         }
         return this.playlistData.currentLangID;
      }
      
      public function get playlistCurrentLangVid() : String {
         if(this.playlistData == null)
         {
            return "";
         }
         return this.playlistData.currentLangVid;
      }
      
      public function getSegmentStatusByNumber(param1:int) : IVideoSegmentStatus {
         if(this.core == null || this.core.getVideoSegmentStatus(param1) == null)
         {
            return new VideoSegmentStatus();
         }
         return this.core.getVideoSegmentStatus(param1);
      }
      
      public function getVideoURL(param1:Boolean = true) : String {
         var _loc2_:* = "http://v.youku.com/v_show/id_";
         _loc2_ = _loc2_ + this.rootData.videoId;
         _loc2_ = _loc2_ + ".html";
         if((param1) && this.rootData.type == "Folder")
         {
            _loc2_ = _loc2_ + ("?f=" + this.rootData.fid);
            if(this.rootData.ob == "0")
            {
               _loc2_ = _loc2_ + "&o=0";
            }
         }
         return _loc2_;
      }
      
      public function getJumpURL() : String {
         var _loc1_:* = "";
         var _loc2_:String = this.getVideoURL();
         if(!(this.rootData.partnerId == null) && !(this.rootData.partnerId == ""))
         {
            _loc1_ = "http://hz.youku.com/outsiteapi.php?";
            _loc1_ = _loc1_ + "tp=3";
            _loc1_ = _loc1_ + ("&pid=" + this.rootData.partnerId);
            _loc1_ = _loc1_ + ("&url=" + _loc2_);
         }
         else
         {
            _loc1_ = "http://player.lstat.youku.com/go.gif?";
            _loc1_ = _loc1_ + "t=3";
            _loc1_ = _loc1_ + "&a=5";
            _loc1_ = _loc1_ + ("&emb=" + this.rootData.embedId);
            _loc1_ = _loc1_ + ("&url=" + _loc2_);
         }
         return _loc1_;
      }
      
      public function getRelativeURL() : String {
         var _loc2_:String = null;
         var _loc3_:String = null;
         var _loc1_:* = "http://v.youku.com/player/getRelatedPlayList?";
         _loc1_ = _loc1_ + ("VideoID=" + this.playlistData.vidEncoded);
         if(this.playlistData.show)
         {
            _loc1_ = _loc1_ + ("&ShowID=" + this.playlistData.show.showID);
         }
         if(this.rootData.type == "Folder")
         {
            _loc1_ = _loc1_ + ("&Fid=" + this.rootData.fid);
            _loc1_ = _loc1_ + ("&Pt=" + this.rootData.pt);
            _loc1_ = _loc1_ + ("&Ob=" + this.rootData.ob);
         }
         var _loc4_:* = "2";
         if(this.playmode == "normal")
         {
            _loc2_ = "1";
         }
         else if(this.playmode == "show")
         {
            _loc2_ = "3";
         }
         else if(this.playmode == "folder")
         {
            _loc2_ = "4";
         }
         
         
         if(this.rootData.winType == "interior")
         {
            _loc3_ = "1";
         }
         else
         {
            _loc3_ = "8";
            _loc2_ = "1";
         }
         _loc1_ = _loc1_ + ("&apptype=" + _loc3_);
         _loc1_ = _loc1_ + ("&page=" + _loc2_);
         _loc1_ = _loc1_ + ("&md=" + _loc4_);
         return _loc1_;
      }
      
      public function get up() : int {
         if(this.playlistData == null)
         {
            return 0;
         }
         return this.playlistData.up;
      }
      
      public function get down() : int {
         if(this.playlistData == null)
         {
            return 0;
         }
         return this.playlistData.down;
      }
      
      public function get tsup() : String {
         if(this.playlistData == null)
         {
            return "";
         }
         return this.playlistData.tokenup;
      }
      
      public function get hashcashup() : String {
         if(this.playlistData == null)
         {
            return "";
         }
         return this.playlistData.hashcashup;
      }
      
      public function get watermark() : Boolean {
         var _loc2_:* = NaN;
         if(this.playlistData == null || this.playlistData.watermarks == null)
         {
            return true;
         }
         var _loc1_:Object = this.playlistData.watermarks;
         if(_loc1_.hasOwnProperty(this.playlistData.fileType))
         {
            _loc2_ = _loc1_[this.playlistData.fileType];
            if(_loc2_ == 0)
            {
               return false;
            }
            if(_loc2_ == 1)
            {
               return true;
            }
         }
         return true;
      }
      
      public function get playmode() : String {
         if(this.playlistData == null)
         {
            return "";
         }
         return this.playlistData.controller.playmode;
      }
      
      public function get paike() : Boolean {
         if(this.playlistData == null)
         {
            return false;
         }
         return this.playlistData.paike;
      }
      
      public function get userData() : IUserData {
         if(this.playlistData == null)
         {
            return null;
         }
         return this.playlistData.user;
      }
      
      public function get previews() : Array {
         if(this.playlistData == null)
         {
            return null;
         }
         if(this.playlistData.previews == null || this.playlistData.previews.length == 0)
         {
            return null;
         }
         return this.playlistData.previews;
      }
      
      public function get circle() : Boolean {
         if(this.playlistData == null)
         {
            return false;
         }
         if(this.playlistData.controller == null)
         {
            return false;
         }
         return this.playlistData.controller.circle;
      }
      
      public function get hd3Enabled() : Boolean {
         if(this.playlistData == null)
         {
            return false;
         }
         if(this.playlistData.controller == null)
         {
            return false;
         }
         return this.playlistData.controller.hd3_enabled;
      }
   }
}
